package crossover;

import java.util.ArrayList;
import java.util.List;

import neural.Individual;

public class ParametrizedUniformCrossover extends AbstractCrossover {
	private double crossProbability;

	public ParametrizedUniformCrossover(double crossProbability) {
		this.crossProbability = crossProbability;
	}


	@Override
	protected List<Individual> generateChilds(Individual father2, Individual mother2) {
		List<Double> father = father2.getWeights();
		List<Double> mother = mother2.getWeights();
		
		List<Double> son1 = new ArrayList<Double>();
		List<Double> son2 = new ArrayList<Double>();
		son1.addAll(father);
		son2.addAll(mother);
		for (int i = 0; i < father.size(); i++) {
			if (Math.random() < crossProbability) {
				son1.set(i, mother.get(i));
				son2.set(i, father.get(i));
			}
		}

		List<Individual> resp = new ArrayList<Individual>();
		resp.add(new Individual(son1));
		resp.add(new Individual(son2));
//		System.out.println("hijo 1" + son1);
//		System.out.println("hijo 2" + son2);
		return resp;
	}
	
}
